package com.sl.au.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.sl.au.entity.Account;
import com.sl.au.entity.EXDEgetPayDetailHistoryWithContract;
import com.sl.au.service.EXDEgetPayDetailHistoryWithContractService;

/**
 * 主机回款明细控制器1
 */
@RestController
@RequestMapping(value="/ui/payHostDetails")
public class PayHostDetailsController extends BaseController{

	@Autowired
	EXDEgetPayDetailHistoryWithContractService exdePayBillingHistoryService;
	
    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView index(){
        ModelAndView modelAndView=createLayoutView("paymentSearch/payHostDetails");
        Account a = this.getMyAccount();
		String userId =a.getUser().getId();
		modelAndView.addObject("userId",userId);
		return modelAndView;
    }
    
    @RequestMapping(value = "getMyTrance", method = RequestMethod.GET)
	public Map<String,Object> getMyTrance(HttpServletRequest request) {
		Map<String,Object> map = new HashMap<String,Object>();
		Map<String,String> condition = new HashMap<String,String>();
		Account a = this.getMyAccount();
		int start = Integer.parseInt(request.getParameter("start"));
		int length = Integer.parseInt(request.getParameter("length"));
		//String chanceId = request.getParameter("chanceId");
		//String userId = a.getUser().getId();
		String superior = a.getUser().getSaleArea().getSuperior();//部门
		//String superior = "销售处";
		String key = request.getParameter("key");
		List<EXDEgetPayDetailHistoryWithContract> users = null;
		String sContractType = request.getParameter("sContractType");
        //condition.put("chanceId", chanceId);
        //condition.put("userId", userId);
		condition.put("key", key);
		condition.put("sContractType", sContractType);
		condition.put("superior", superior);
		users = exdePayBillingHistoryService.getMyPage(start, length, condition);
        long count = exdePayBillingHistoryService.getMyPageCount(start, length, condition);
		
		map.put("data", users);
		map.put("draw", request.getParameter("draw"));
		map.put("recordsFiltered", count);
		map.put("recordsTotal", count);
		return map;
	}
}
